package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesEquipmentRunningRecord;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesEquipmentRunningRecordDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:26:41
 */
public class MesEquipmentRunningRecordConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesEquipmentRunningRecordConverts.class);

    public static List<MesEquipmentRunningRecordDTO> convert(List<MesEquipmentRunningRecord> mesEquipmentRunningRecordList) {
        if (CollectionUtils.isEmpty(mesEquipmentRunningRecordList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesEquipmentRunningRecordDTO> mesEquipmentRunningRecordListResult = Lists.newArrayList();
        for (MesEquipmentRunningRecord mesEquipmentRunningRecord : mesEquipmentRunningRecordList) {
            mesEquipmentRunningRecordListResult.add(convert(mesEquipmentRunningRecord));
        }
        return mesEquipmentRunningRecordListResult;
    }

    public static MesEquipmentRunningRecordDTO convert(MesEquipmentRunningRecord mesEquipmentRunningRecord) {
        try {
            return BeanUtils.copy(mesEquipmentRunningRecord, MesEquipmentRunningRecordDTO.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentRunningRecord到MesEquipmentRunningRecordDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentRunningRecord到MesEquipmentRunningRecordDTO转换失败", e);
        }
    }

    public static MesEquipmentRunningRecord convert(MesEquipmentRunningRecordDTO mesEquipmentRunningRecordDTO) {
        try {
            return BeanUtils.copy(mesEquipmentRunningRecordDTO, MesEquipmentRunningRecord.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentRunningRecordDTO到MesEquipmentRunningRecord转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentRunningRecordDTO到MesEquipmentRunningRecord转换失败", e);
        }
    }
}